package com.mm.cloud.common.mq.config;

import com.mm.cloud.common.mq.enums.ExchangeEnum;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 交换机配置
 *
 * @author mr
 * @since 2021-06-30
 */
@Configuration
public class ExchangeConfig {

    /**
     * 持久化的一对一交换机
     */
    @Bean
    public DirectExchange directExchange() {
        //交换机名称 durable-消息持久化 autoDelete-自动删除
        return new DirectExchange(ExchangeEnum.DIRECT.getKey(), true, false);
    }

    /**
     * 持久化的规则匹配交换机
     */
    @Bean
    public TopicExchange topicExchange() {
        //交换机名称 durable-消息持久化 autoDelete-自动删除
        return new TopicExchange(ExchangeEnum.TOPIC.getKey(), true, false);
    }

    /**
     * 消息广播交换机
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        //交换机名称 durable-消息持久化 autoDelete-自动删除
        return new FanoutExchange(ExchangeEnum.FANOUT.getKey(), true, false);
    }

}
